package com.sitanyun.merchant.guide.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sitanyun.merchant.guide.R;
import com.sitanyun.merchant.guide.bean.TrajeBean;
import com.sitanyun.merchant.guide.weiht.NoScrollListView;

import java.util.List;

/**
 * Created by jzl
 * on 2022/1/13.
 * 轨迹主列表
 */
public class TrajeListAdapter extends BaseAdapter {
    private Context context;
    private List<TrajeBean.DataBean> tralists;


    public TrajeListAdapter(Context context, List<TrajeBean.DataBean> tralists) {
        this.context = context;
        this.tralists = tralists;
    }

    @Override
    public int getCount() {
        return tralists.size();
    }

    @Override
    public Object getItem(int position) {
        return  tralists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    convertView= LayoutInflater.from(context).inflate(R.layout.tralist_item,null);
        TextView create_time= convertView.findViewById(R.id.create_time);
        create_time.setText(tralists.get(position).getDate());
       TextView shar= convertView.findViewById(R.id.shar);

        View views= convertView.findViewById(R.id.views);
        if (position>0){
            views.setVisibility(View.VISIBLE);
        }else {
            views.setVisibility(View.INVISIBLE);
        }
        shar.setText("浏览"+tralists.get(position).getBrowseNum()+"次");
       TextView shar_times= convertView.findViewById(R.id.shar_times);
        int intTime= tralists.get(position).getDuration();
        int h=intTime/3600;
        int m=(intTime%3600)/60;
        int s=(intTime%3600)%60;
        if (h==0){
            shar_times.setText("活动时长"+m+"分"+s+"秒");
        }else {
            shar_times.setText("活动时长"+h+"时"+m+"分钟");
        }
        NoScrollListView   mlistView = (NoScrollListView) convertView.findViewById(R.id.list_traje);
        TrajeListsAdapter trajeListsAdapter= new TrajeListsAdapter(context,tralists.get(position).getList());
        mlistView.setAdapter(trajeListsAdapter);

      return convertView;
    }
}
